# Doxygen support
include $(top_srcdir)/doxygen/aminclude.am

AUTOMAKE_OPTIONS = foreign
ACLOCAL_AMFLAGS  = -I m4 -I m4/common

SUBDIRS          = src test doxygen share examples
EXTRA_DIST       = CHANGES LICENSE COPYING share

# Eliminate .svn directories in dist tarball
# Also hacking around EXTRA_DIST not dealing with
# the antioch.m4 symlink correctly. So we manually
# deal with it. Also, by default, it seems permissions
# don't let us remove stuff, we chmod it before
# trying to remove stuff.
dist-hook:
	chmod -R u+w $(distdir)
	rm -rf $(distdir)/share/aclocal/antioch.m4
	cp -L $(top_srcdir)/share/aclocal/antioch.m4 $(distdir)/share/aclocal

# Tools in the auxiliary directory
AUX_DIST         = build-aux/install-sh
AUX_DIST        += build-aux/missing
AUX_DIST        += build-aux/config.guess
AUX_DIST        += build-aux/config.sub
AUX_DIST        += build-aux/depcomp
AUX_DIST        += build-aux/ltmain.sh

# Support for pkgconfig
pkgconfigdir   = $(libdir)/pkgconfig
pkgconfig_DATA = antioch.pc

# Support 'make install prefix=/other/path' with pkgconfig
install-data-hook:
	@if (test "x$(prefix)" != "x@prefix@"); then \
	  oldprefix="@prefix@" ; \
	  newprefix="$(prefix)" ; \
	  cd $(DESTDIR)$(libdir)/pkgconfig ; \
	  for genfile in $(pkgconfig_DATA); do \
	  echo " " ; \
	    echo " *** replacing $$oldprefix" ; \
	    echo " ***      with $$newprefix" ; \
	    echo " *** in generated file $$genfile" ; \
	    echo " " ; \
	    cd $(DESTDIR)$(prefix) && cat $$genfile | $(SED) "s,$$oldprefix,$$newprefix,g" > $$genfile.replaced ; \
	    cd $(DESTDIR)$(prefix) && mv $$genfile.replaced $$genfile ; \
          done ; \
	fi
	cd $(DESTDIR)$(includedir) && cat antioch_config.h | $(SED) "s,\(define ANTIOCH_DEFAULT_FILES_PATH\).*$$,\1 "\"@datadir@/antioch_default_files/\""," > config.replaced ; \
	cd $(DESTDIR)$(includedir) && mv config.replaced antioch_config.h ;

# Install config file
BUILT_SOURCES = antioch_config.h
include_HEADERS	= antioch_config.h

# Additional files to be deleted by 'make distclean'
DISTCLEANFILES  = _configs.sed
DISTCLEANFILES += antioch_config.h

MOSTLYCLEANFILES  =
MOSTLYCLEANFILES += $(DX_CLEANFILES)
MOSTLYCLEANFILES += docs/lcov

# Files to be deleted by 'make maintainer-clean'
MAINTAINERCLEANFILES  = aclocal.m4
MAINTAINERCLEANFILES += aminclude.am
MAINTAINERCLEANFILES += autom4te.cache/*
MAINTAINERCLEANFILES += $(AUX_DIST)
MAINTAINERCLEANFILES += config.log
MAINTAINERCLEANFILES += config.status
MAINTAINERCLEANFILES += config.sub
MAINTAINERCLEANFILES += configure
MAINTAINERCLEANFILES += antioch_config.h.tmp.in
MAINTAINERCLEANFILES += antioch_config.h.tmp.in~
MAINTAINERCLEANFILES += Makefile.in
MAINTAINERCLEANFILES += src/Makefile.in
MAINTAINERCLEANFILES += test/Makefile.in
MAINTAINERCLEANFILES += doxygen/Makefile.in
MAINTAINERCLEANFILES += m4/libtool.m4
MAINTAINERCLEANFILES += m4/ltoptions.m4
MAINTAINERCLEANFILES += m4/ltsugar.m4
MAINTAINERCLEANFILES += m4/ltversion.m4
MAINTAINERCLEANFILES += m4/lt~obsolete.m4

#---------------------------------
# Embedded license header support
#---------------------------------
# PB: I'm leaving this here commented out in case the AC_SUBST solution
#     dies at some point. The below requires GNU make and causes a
#     an Automake warning (that can be suppressed with -Wno-portability)
#     so I went for the more general solution instead, but the below
#     works.
#STAMPED_FILES  = $(shell find $(top_srcdir)/src -name '*.h' -or -name '*.C')

# Since we don't distribute the lic_utils, check and make sure it's there.
# This way, we won't run this on distributed tarballs, only on the repos clones
if ANTIOCH_LICENSESTAMPEXISTS
BUILT_SOURCES += .license.stamp
.license.stamp: $(top_srcdir)/LICENSE
	@$(top_srcdir)/src/common/lic_utils/update_license.pl $(top_srcdir)/LICENSE $(ANTIOCH_STAMPED_FILES)
	echo 'updated source license headers' >$@

CLEANFILES = .license.stamp
endif

# -------------------------------------------
# Optional support for code coverage analysis
# -------------------------------------------

if CODE_COVERAGE_ENABLED

lcov_dir=$(top_builddir)/docs/lcov/html

# General philosophy is to maintain code coverage for the
# base library as generated by "make check" tests.

lcov-report:
	@mkdir -p $(lcov_dir)

	$(top_srcdir)/src/common/lcov/lcov --compat-libtool --directory . --capture --output-file $(lcov_dir)/lcov.info
	$(top_srcdir)/src/common/lcov/lcov --list-full-path -l $(lcov_dir)/lcov.info | grep -v "`cd -P $(top_srcdir)/src && pwd`" | cut -d\| -f1 > $(lcov_dir)/remove
	$(top_srcdir)/src/common/lcov/lcov -q -r $(lcov_dir)/lcov.info `cat $(lcov_dir)/remove` > $(lcov_dir)/lcov.cleaned.info
	@rm $(lcov_dir)/remove
	@mv $(lcov_dir)/lcov.cleaned.info $(lcov_dir)/lcov.info
	$(top_srcdir)/src/common/lcov/genhtml -t "Antioch" -o $(lcov_dir) $(lcov_dir)/lcov.info

lcov-reset:
	@rm -rf $(lcov_dir)
	@find . -name "*.gcda" -exec rm {} \;
	$(top_srcdir)/src/common/lcov/lcov --directory . --zerocounters

coverage: lcov-reset check lcov-report

endif
